package com.jctf.net;

import java.io.FileOutputStream;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class FileDownloadTest {

	private static final String FILE_NAME = "testdl.txt"; 
	
	public static void main(String[] args) {
		try {
			System.out.print("Starting...");
			URL site = new URL("http://spoon.dontexist.com/" + FILE_NAME);
			ReadableByteChannel rbc = Channels.newChannel(site.openStream());
			FileOutputStream fos = new FileOutputStream("downloadedFile.txt");
			fos.getChannel().transferFrom(rbc, 0, 1 << 24);
			System.out.println("done.");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
